package edu.thu.studio.ormdesigner.editor.dialog.tab.view;

import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Text;

import edu.thu.studio.ormdesigner.common.AbstractTabbedDialog;
import edu.thu.studio.ormdesigner.common.CompositeFactory;
import edu.thu.studio.ormdesigner.common.InputException;
import edu.thu.studio.ormdesigner.common.ValidatableTabWrapper;
import edu.thu.studio.ormdesigner.model.orm.view.View;
import edu.thu.studio.ormdesigner.util.Properties;
import edu.thu.studio.ormdesigner.util.Utils;

public class SQLTabWrapper extends ValidatableTabWrapper {
    
    private Text sqlText;
    
    private View ormView;
    
    public SQLTabWrapper(AbstractTabbedDialog dialog, TabFolder parent,View ormView) {
        super(dialog, parent, Properties.diagram_label_view_sql);
        this.ormView = ormView;
    }
    
    @Override
    public void validatePage() throws InputException {
        
    }
    
    @Override
    protected void initComposite() {
        this.sqlText = CompositeFactory.createTextArea(null, this, null, 600, 300, 1, true);
    }
    
    @Override
    protected void setData() {
    	super.setData();
    	if(null!=this.ormView){
    		this.sqlText.setText(Utils.null2blank(this.ormView.getSql()));
    	}
    }
    
    @Override
    public void perfomeOK() {
    	this.ormView.setSql(this.sqlText.getText().trim());
    }
    
    @Override
    public void setInitFocus() {
        
    }
    
}
